<template>
  <div class="app-container flex-col minH">
    <div class="topline w100p bgwhite ptb20 radius10 pl10 pr20 justify-between">
      <div>
        <el-input v-model="id" style="width: 280px" placeholder="搜尋序號..." :prefix-icon="Search" class="search" />


      </div>
      <div class="noshrink">
        <el-button class="btn2" @click="getChargeRuleList()">查詢</el-button>
        <el-button class="btn1" @click="reset()">重置</el-button>
      </div>
    </div>
    <div class="mt15 radius10 hidden pb15 flex1 bgwhite  flex-col w100p">
      <div class="flex1 w100p ">
        <el-table :data="tableData" style="width: 100%" cell-class-name="tbcell" header-cell-class-name="hdcell">

          <el-table-column prop="id" label="用戶訊息" />
          <el-table-column prop="money" label="提款方式" />
          <el-table-column prop="votes" label="充值金額" />
          <el-table-column prop="votes" label="訂單號" />
          <el-table-column prop="votes" label="狀態" />


          <el-table-column prop="created_at" label="創建時間" />
        </el-table>
      </div>

      <div class=" justify-between plr20 w100p mt15">
        <div class="align-center">
        </div>
        <el-pagination v-model:current-page="currentPage" prev-text="上一頁" next-text="下一頁" :default-page-size="15" :background="true" layout="prev, pager, next, jumper" :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
      </div>
    </div>

  </div>
</template>

<script setup lang="ts">
import { Search } from '@element-plus/icons-vue'
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router';
import { ElTable } from 'element-plus'
import { chargeRuleList, chargeRuleDelete } from '@/api/finance.js'
onMounted(() => {
  getChargeRuleList()
})

// 充值规则列表
const getChargeRuleList = () => {
  chargeRuleList({
    page: currentPage.value,
    id: id.value
  }).then((res) => {
    console.log('充值规则列表', res)
    tableData.value = res.data.data
    total.value = res.data.total
  })
}
const idStr = ref('')
const handleSelectionChange = (e) => {
  let idList = e.map((item, index) => { return item.id })
  idStr.value = idList.join(',')
  console.log(idList)
}
const batchDel = () => {
  chargeRuleDelete({
    id: idStr.value
  }).then(() => {
    getChargeRuleList()
  })
}
const id = ref('')
const reset = () => {
  id.value = ''
  getChargeRuleList()
}



const multipleTableRef = ref<InstanceType<typeof ElTable>>()


const tableData = ref([])
const currentPage = ref(1)
const total = ref(0)
const handleSizeChange = (val) => {
  console.log(`${val} items per page`)
}
const handleCurrentChange = (val) => {
  console.log(`current page: ${val}`)
  getChargeRuleList()
}
const router = useRouter()
const toAdd = () => {
  console.log(router)
  router.push({ path: 'editPage', query: { type: 'ruleAdd' } })
}
const edit = (row) => {
  router.push({ path: 'editPage', query: { ...row, type: 'ruleEdit' } })
}
</script>

<style lang="scss" scoped>
.search {
  overflow: hidden;
  border-radius: 10px !important;
  // padding: 5px 0px;
}
</style>
<style></style>
